Screen Coordinates
Engine uses float-based, resolution independent screen coordinates.
This means that the screen coordinates are not per-pixel.
Please see the following image with screen proportions highlighted:
Under default engine settings the visible screen has:
- Horizontal (X) Range calculated proportionally to selected screen resolution, for example:
- Aspect Ratio 5:4 (resolution 1280x1024) Range -1.25 .. 1.25 (Blue Rectangle)
- Aspect Ratio 4:3 (resolution 1024x768) Range -1.33 .. 1.33 (Green Rectangle)
- Aspect Ratio 16:10 (resolution 1680x1050) Range -1.60 .. 1.60 (Red Rectangle)
- Vertical (Y) Range -1 .. 1
You can also notice that:
- Screen Center is at (0,0) coordinates
- Horizontal (X) Coordinates increase towards Right direction
- Vertical (Y) Coordinates increase towards Up direction
Working with Different Resolutions
When designing a Gui System you can assume that no matter which resolution you'll choose:
- The Y Range will always be -1 .. 1
- The X Range will be dependent on the monitor size - for some monitors it will be -1.25 .. 1.25, and for some widescreen monitors it will be -1.60 .. 1.60.
Meaning that some monitors will give more horizontal space on the left and right sides.
Window Child Coordinates
In the Gui Desktop the (0,0) position specifies the center of the accessible area.
Gui Child Objects (like Text or Button) in Gui Windows are positioned relatively to the Gui Windows, and there the (0,0) position is not the Window center, but the Window top left corner:
- w - Window Width
- h - Window Height
Programming
At all times visible screen range can be accessed by engine methods D.w() and D.h(), which specify:
- Horizontal (X) Range -D.w() .. D.w()
- Vertical (Y) Range -D.h() .. D.h()
Screen Coordinates can be modified by some of engine methods:
- D.scale() - uniformly scales the screen ranges by custom factor
- D.aspectMode() - can make Horizontal (X) Range always in range -1 .. 1 and make Vertical (Y) Range calculated proportionally
- D.aspectRatio() - can adjust the aspect ratio of the display screen